package main

import (
	"log"
	"os"

	"gitee.com/lishixi/gops/book/api"
	"gitee.com/lishixi/gops/book/config"
	"github.com/gin-gonic/gin"
)

// 规定好风格: JSON Restful Api
func main() {
	path := os.Getenv("CONFIG_PATH")
	if path == "" {
		path = "application.yaml"
	}
	if err := config.LoadConfigFromYamlFile(path); err != nil {
		log.Fatal("加载配置错误", err)
		os.Exit(1)
	}

	conf := config.Get()

	// gin Engine, 它包装了http server
	server := gin.Default()

	// db := conf.MySQL.DB()
	// db.AutoMigrate(&models.Book{})
	api.NewBookApiHandler().Register(server)

	if err := server.Run(conf.App.Addr()); err != nil {
		log.Println(err)
	}
}
